package com.project_doctor.mapper;

import com.project_doctor.pojo.Message;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
/**
* @author 龙龙与贝儿
* @description 针对表【t_message】的数据库操作Mapper
* @createDate 2025-06-07 11:22:51
* @Entity com.project_doctor.pojo.Message
*/
public interface MessageMapper extends BaseMapper<Message> {

    @Select("SELECT " +
            "m.*, " +
            "d.id as doctor_id, d.name as doctor_name, d.avatar as doctor_avatar " +
            "FROM t_message m " +
            "LEFT JOIN t_doctor d ON m.sender_id = d.id " +
            "WHERE m.conversation_id = #{conversationId} " +
            "ORDER BY m.id ASC")
    @Results({
            @Result(property = "id", column = "id", id = true),

            @Result(property = "sender.id", column = "doctor_id"),
            @Result(property = "sender.name", column = "doctor_name"),
            @Result(property = "sender.avatar", column = "doctor_avatar")
    })
    List<Message> getMessagesByConversationId(Long conversationId);
}




